<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Page super utilisateur</title>
	
  	<link rel="stylesheet" href="<c:url value="/resources/Styles/styles.css"/>"/>
	<script src="<c:url value="/resources/js/jquery-1.8.3.js"/>"></script>

  	<script>

  	function validerParticipation(id){
		$.ajax({
			type: "POST",
			url: "<c:url value="validerParticipation"/>",
			data: "id=" + id,
			success: function(response){
				if(response == "erreur1"){
					alert('Erreur : application non terminée par utilisateur');
				}else if(response == "erreur2"){
					alert('Erreur : application déja validée');
				}else if(response == "erreur3"){
					alert('Erreur : mauvaise réponse');
				}else{
					alert('application validée avec succées');
				}
				window.location.href = "<c:url value="/superuser/showParticipations"/>";
			},
			error: function(e){
				
			}
		});
  	}

  	function refuserParticipation(id){
		$.ajax({
			type: "POST",
			url: "<c:url value="refuserParticipation"/>",
			data: "id=" + id,
			success: function(response){
				if(response == "erreur1"){
					alert('Erreur : application non terminée par utilisateur');
				}else if(response == "erreur2"){
					alert('Erreur : application déja refusée');
				}else{
					alert('application refusée avec succées');
				}
				window.location.href = "<c:url value="/superuser/showParticipations"/>";
			},
			error: function(e){
				
			}
		});
  	}

</script>
  	
</head>
<body>

<form:form method="post" commandName="ParticipationsSuperUserForm" id="form">

<div align="center"><h3><spring:message code="index.listeParticipations"/></h3></div>

<table id="tableView" align="center" border="1" width="1000">

	<tr>
		<th width="20%">Utilisateur</th>
		<th width="20%">Application</th>
		<th width="15%">Statut</th>
		<th width="20%">Reponses</th>
		<th width="25%">DateMaj</th>
		<th width="10%">Actions</th>
	</tr>

	<c:forEach items="${listParticipation}" var="participation">
	<tr >

		<td>${participation.user}</td>
		<td>${participation.application}</td>
		<td>${participation.statutParticipation}</td>
		<td>${participation.reponses}</td>
		<td>${participation.dateMajStr}</td>

		<td>
			<a onclick="javascript:validerParticipation(${participation.id})">
				<img src="<c:url value="/resources/img/valider.png"/>" title="valider">
			</a>
			<a onclick="javascript:refuserParticipation(${participation.id})">
				<img src="<c:url value="/resources/img/delete.png"/>" title="refuser">
			</a>
		</td>
	
	</tr>
	</c:forEach>

</table>

<form:hidden path="idApp" id="idApp"/>

</form:form>
</body>
</html>